package com.hywood.app.live.liveinterface;


import com.hywood.app.live.feignfallback.AbstractChannelFeignFallBack;
import com.hywood.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created By HuJian on 2018/7/18
 */
@Component
@Api("channelInterface")
@FeignClient(name = "live-app-service", fallback = AbstractChannelFeignFallBack.class)
public interface ChannelInterface {
    /**
     * 获取频道列表
     * @param index 页码
     * @param size 分页大小
     * @return 分页后数据
     */
    @ApiOperation(value = "获取频道列表", notes = "获取频道列表")
    @RequestMapping(method = RequestMethod.GET, value = "/listchannel/{index}")
    Result listChannel(@ApiParam(value = "页码",required = true)Integer index,
                       @ApiParam(value = "分页大小",required = true)Integer size);

    /**
     * 通过guid获取频道详细信息
     * @param guid 频道guid
     * @return 频道信息
     */
    @ApiOperation(value = "获取频道详细信息", notes = "获取频道详细信息")
    @RequestMapping(method = RequestMethod.GET, value = "/channel/{guid}")
    Result getChannelByGuid(@ApiParam(value = "频道guid",required = true)String guid);
    /**
     * 直播鉴权
     * @param channelId 频道id
     * @param password 频道密码，hash后密文传输,暂时使用md5实现
     * @return 如果成功则返回直播鉴权后连接地址
     */
    @ApiOperation(value = "直播鉴权", notes = "直播鉴权")
    @RequestMapping(method = RequestMethod.GET, value = "/verifyPrivilege/{appname}/{channelId}")
    Result verifyPrivilege(@ApiParam(value = "应用名称",required = true) String appName,
                           @ApiParam(value = "频道ID",required = true)String channelId,
                           @ApiParam(value = "频道密码，明文密码MD5加密后的小写字符串",required = true)String password);

    /**
     * 获取直播拉流地址
     * @param appName appname
     * @param channelGuid 频道guid 如果有转码，则在guid后拼上_转码模板
     * @param type 视频类型，m3u8或者rtmp
     * @return 返回带鉴权的拉流地址
     */
    @ApiOperation(value = "获取直播拉流地址", notes = "获取直播拉流地址")
    @RequestMapping(method = RequestMethod.GET, value = "/pulluri/{appname}/{channelGuid}")
    Result getPullUri(@ApiParam(value = "应用名称",required = true)String appName,
                      @ApiParam(value = "频道guid",required = true)String channelGuid,
                      @ApiParam(value = "流类型，支持rtmp和m3u8",required = true)String type);

    /**
     * 阿里回调地址
     * @param action 推流或者断流
     * @param app 推流域名
     * @param appname appname
     * @param id 频道guid
     * @param node 推流节点
     * @param IP 客户端ip
     * @param usrargs 用户推流的参数
     * @param time 阿里时间戳
     * @return 成功
     */
    @ApiOperation(value = "阿里直播状态回调接口", notes = "阿里直播状态回调接口")
    @RequestMapping(method = RequestMethod.GET, value = "/alivccallback")
    Result alivcStatusCallBack(@ApiParam(value = "publish 表示推流，publish_done 表示断流",required = true)String action,
                               @ApiParam(value = "默认为自定义的推流域名，如果未绑定推流域名即为播放域名",required = true)String app,
                               @ApiParam(value = "应用名称",required = true)String appname,
                               @ApiParam(value = "流名称",required = true)String id,
                               @ApiParam(value = " CDN 接受流的节点或者机器名",required = true)String node,
                               @ApiParam(value = "推流的客户端 IP",required = true)String IP,
                               @ApiParam(value = "用户推流的参数",required = true)String usrargs,
                               @ApiParam(value = "unix 时间戳",required = true)String time);

    /**
     * 暂停直播
     * @param guid 频道guid
     * @return 操作结果
     */
    @ApiOperation(value = "暂停直播", notes = "暂停直播")
    @RequestMapping(method = RequestMethod.PUT, value = "/livepause/{guid}")
    Result livePause(@ApiParam(value = "频道guid",required = true)String guid);

    /**
     * 恢复直播
     * @param guid 频道guid
     * @return 操作结果
     */
    @ApiOperation(value = "恢复直播", notes = "恢复直播")
    @RequestMapping(method = RequestMethod.PUT, value = "/liverecovery/{guid}")
    Result liveRecovery(@ApiParam(value = "频道guid",required = true)String guid);
}
